<%@page import="info.hengha.blue.dao.*,info.hengha.blue.model.*,java.util.*" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html>
    <head>
        <%@ include file="/WEB-INF/jspf/meta.jspf" %>
        <title>OpenStack & Docker JSP&Servlet Load Balance</title>
        <%@ include file="/WEB-INF/jspf/css.jspf" %>
    </head>
    <body>
        <jsp:include page="/WEB-INF/jspf/menu.jsp">
            <jsp:param name="current" value="about" />
        </jsp:include>
        <div class="container theme-showcase" role="main">
            <%
                CategoryDao dal = new CategoryDao();
                if (request.getMethod() == "POST") {
                    Category model = new Category();
                    model.setName(request.getParameter("name"));
                    model.setSlug(request.getParameter("slug"));
                    /*
                    model.setType("category");
                    model.setParentId(Integer.parseInt(request.getParameter("parentId")));
                    dal.add(model);
                            */
                    response.sendRedirect("categories.jsp");
                }
                List<Category> categories = dal.getCategories();
                request.setAttribute("categories", categories);
            %>
            <form method="post" class="form">
                <input type="text" name="name" placeholder="Name" />
                <input type="text" name="slug" placeholder="Slug" />
                <select name="parentId">
                    <option value="0"></option>
                    <c:forEach items="${categories}" var="category">
                        <option value="${category.id}">${category.name}</option>
                    </c:forEach>
                </select>
                <button type="submit" class="btn btn-primary">Add</button>
            </form>
            <table class="table">
                <thead>
                    <tr>
                        <th>Id</th>
                        <th>Name</th>
                        <th>Slug</th>
                        <th>Aliases</th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${categories}" var="category">
                        <tr>
                            <td>${category.id}</td>
                            <td><a href="#${category.id}">${category.name}</a></td>
                            <td>${category.slug}</td>
                            <td></td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </div>
        <%@ include file="/WEB-INF/jspf/js.jspf" %>
    </body>
</html>